import java.util.Arrays;

public class Test {

        //数组逆序
    public static void reverse(int[] array) {
        int i = 0;
        int j = array.length-1;
        while (i < j) {
            swap(array,i,j);
            i++;
            j--;
        }
    }
    public static void swap(int[] array,int i,int j) {
        int tmp= 0;
        tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }

    public static void main3(String[] args) {
        int[] array = {1,2,3,4,5};
        reverse(array);
        String ret = Arrays.toString(array);
        System.out.println("逆序后的数组为"+ret);
    }



    //自己实现Arrays.toString方法功能
    public static String myToString(int[] array) {
        String ret = "[";

        for (int i = 0; i < array.length; i++) {
            ret += array[i];

            if (i != array.length-1) {
                ret += ",";
            }
        }

        ret += "]";

        return ret;
    }
    public static void main2(String[] args) {
        int[] array = {1,2,3,4,5};
        String ret = myToString(array);
        System.out.println(ret);
    }

    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5};
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }
}
